package com.xhwl.logistics.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xhwl.common.dto.cent.device.DeviceDTO;
import com.xhwl.common.enums.CodeEnum;
import com.xhwl.common.pojo.ResultJson;
import com.xhwl.common.pojo.cent.device.Device;
import com.xhwl.common.query.cent.device.DevicePageQuery;
import com.xhwl.common.query.cent.vehicle.DeviceQuery;
import com.xhwl.logistics.service.IVehcDeviceService;
import com.xhwl.common.vo.cent.vehicle.DeviceVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Lu.Aaron
 * @since 2021-02-08
 */
//@RestController
@Api(tags = "车行设备")
@Slf4j
@RequestMapping("/device")
public class VehcDeviceController {
    @Autowired
    private IVehcDeviceService vehcDeviceService;


    @ApiOperation(value = "修改设备",notes = "输入框有required标识的字段为必填项", response = ResultJson.class, httpMethod = "POST")
    @ResponseBody
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public ResultJson update(@ApiParam(value = "body字段含义请看model",required = true)@RequestBody DeviceVO deviceVO,@RequestHeader Short industryId) {

        vehcDeviceService.edit(deviceVO,industryId);
        return  new ResultJson(true, CodeEnum.SUCCESS.getCode(),"修改成功");
    }


    @ApiOperation(value = "设备管理分页",notes = "输入框有required标识的字段为必填项", response = ResultJson.class, httpMethod = "POST")
    @ResponseBody
    @RequestMapping(value = "/page", method = RequestMethod.POST)
    public ResultJson devicePage(@RequestBody DeviceQuery deviceQuery,@RequestHeader Short industryId) {
        Page<DeviceDTO> deviceDTOPage =vehcDeviceService.devicePage(deviceQuery,industryId);
        return  new ResultJson(true, CodeEnum.SUCCESS.getCode(),"查询成功",deviceDTOPage);
    }

    @ApiOperation(value = "设备详情",notes = "输入框有required标识的字段为必填项", response = ResultJson.class, httpMethod = "GET")
    @ResponseBody
    @RequestMapping(value = "/list-device", method = RequestMethod.POST)
    public ResultJson listdevice(@RequestBody DevicePageQuery devicePageQuery, @RequestHeader Short industryId) {
        List<Device> device =vehcDeviceService.listdevice(devicePageQuery,industryId);
        return ResultJson.success(device);
    }

}

